<?php
include("../user/userlogincheck.php");
include("../include/config.inc.php");

$code=uuid();

$sql="select * from ".tableprefix."store where member_id='$userid'";
$result=$db->query($sql);
$row = $db->fetch_array($result);
$store_id=$row["store_id"];
$store_name=$row["store_name"];
if($store_id==''){
	echo("<script type='text/javascript'>location.href='store.php';</script>");
	exit;
}

$todo=$_REQUEST["todo"];
if(isset($todo) && $todo=="todo"){
	$title = $_POST['title'];
	$gc_id = $_POST['gc_id'];
	$price = $_POST['price'];
	$book_price = $_POST['book_price'];
	$content = $_POST['content'];
	$code = $_POST['code'];

	$ap="";
  	$temp_x=$_POST[posTypeSelect];
  	for($i=0;$i<count($temp_x);$i++){ 
  		$ap=$ap.$temp_x[$i].",";
		$a=$temp_x[$i];		
		$time=date("Y-m-d H:i:s",time());
		$sql="insert into ".tableprefix."datetime(date,code,createtime,ip,flag)values('$a','$code','$time','".getIP()."','T')";
		$db->query($sql);		
  	}
  	$z=substr($ap,0,-1);//去除末尾单引号职位分类
	
	if($title==""){
		echo "<script>alert('请输入标题！');history.back(-1);</script>";
		exit;
	}
	if($price==""){
		echo "<script>alert('请输入价格！');history.back(-1);</script>";
		exit;
	}
	if($book_price==""){
		echo "<script>alert('请输入订金价格！');history.back(-1);</script>";
		exit;
	}
	if($z==""){
		echo "<script>alert('请选择演出日期！');history.back(-1);</script>";
		exit;
	}
	if($content==""){
		echo "<script>alert('请输入内容！');history.back(-1);</script>";
		exit;
	}
	$sql_img="select * from ".tableprefix."img where code='$code' order by id ASC limit 0,1";
	$res_img=$db->query($sql_img);
	$row_img = $db->fetch_array($res_img);
	$goods_image=$row_img["imgpath"];
	if($goods_image==""){
		echo "<script>alert('请上传缩略图！');history.back(-1);</script>";
		exit;
	}
	
	$sql="insert into ".tableprefix."goods(goods_name,gc_id,store_id,store_name,code,goods_image,showdate,goods_price,book_down_payment,goods_body,goods_addtime,goods_state)values('$title','$gc_id','$store_id','$store_name','$code','$goods_image','$z','$price','$book_price','$content','".time()."','1')";	
	$db->query($sql);
	if(!$db->error())
	{
		echo "<script>alert('发布成功！');location.href='index.php';</script>";
		$db->close();
		exit;
	}
	else
	{
		echo "<script>alert('数据库出错，请重新发布。');location.href='index.php';</script>";
		$db->close();
		exit;
	}
}
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>演出信息发布 - 订戏会</title>
<meta name="renderer" content="webkit">
<meta http-equiv="X-UA-Compatible" content="IE=9,Chrome=1">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
<meta name="apple-mobile-web-app-capable" content="yes" />
<meta name="apple-mobile-web-app-status-bar-style" content="black" />
<link rel="stylesheet" type="text/css" href="../js/frameJS/layer/mobile/need/layer.css"/>
<link rel="stylesheet" type="text/css" href="../css/frameCss/bootstrap.min.css"/>
<link rel="stylesheet" type="text/css" href="../css/frameCss/animate.css" />
<link rel="stylesheet" type="text/css" href="../css/public.css">
<link rel="stylesheet" type="text/css" href="../css/publish.css">
<link href="../css/src/ui-choose.css" rel="stylesheet" />
<script language="javascript" type="text/javascript"> 
function showTime(){ 
document.store_navigation_form.content.value=document.getElementById("content").innerHTML;
} 
setInterval("showTime()",1000); 
</script>
</head>

<body>
<div class="head-nav">
	<div class="head-left"><a href="#1"><div class="back">返回</div></a></div>
	<div class="head-center">演出信息发布</div>
	<div class="head-right"><a href="#"><div class="shuoming"></div></a></div>
</div>
<div class="remind"><p>演出信息发布</p></div>

<form action="" method="post" name="store_navigation_form" id="store_navigation_form" enctype="multipart/form-data">
<input name="todo" type="hidden" value="todo">
<input name="code" type="hidden" value="<?php echo $code;?>">
<input name="content" type="hidden" value="">
<div class="mod-form">
	<div class="form-group">
		<div class="form-cell">
			<ul>
				<li><input type="text" id="title" name="title" placeholder="请填写标题" value=""></li>		
			</ul>
		</div>
		<div class="form-item">
			<label>分类</label>
			<select name="gc_id">
<?php
$res_class = $db->query("select * FROM ".tableprefix."goods_class where flag='T' ORDER BY gc_sort DESC,gc_id ASC");
while($class = $db->fetch_array($res_class)){?>
 				<option value="<?php echo $class["gc_id"];?>"><?php echo $class["gc_name"];?></option>
<?php
}
?>
			</select>
		</div>
		<div class="form-item">
			<label>价格</label>
			<input type="text" pattern="[0-9]*" maxlength="8" id="price" name="price" placeholder="请填写演出价格" value="">
			<span>元</span>
		</div>
		<div class="form-item">
			<label>订金</label>
			<input type="text" pattern="[0-9]*" maxlength="8" id="book_price" name="book_price" placeholder="请填写订金金额" value="">
			<span>元</span>
		</div>
		<div class="form-img">
			<a class="file" href="javascript:;">
				<span>上传图片</span>
				<input type="file" name="file" id="uploadThumb">
			</a>
			<ul id="imgList"></ul>
		</div>
	</div>
	<div class="form-group">
		<div class="form-date">
			<h1>选择演出日期</h1>
			<ul>
				<li>日</li>
				<li>一</li>
				<li>二</li>
				<li>三</li>
				<li>四</li>
				<li>五</li>
				<li>六</li>
			</ul>
			<span>2017年9月</span>
			<select class="ui-choose" multiple="multiple" id="uc_04" name="posTypeSelect[]">
				<option></option>
				<option></option>
				<option></option>
				<option></option>
				<option></option>
				<option value="2017-09-01">1</option>
				<option value="2017-09-02">2</option>
				<option value="2017-09-03">3</option>
				<option value="2017-09-04">4</option>
				<option value="2017-09-05">5</option>
				<option value="2017-09-06">6</option>
				<option value="2017-09-07">7</option>
				<option value="2017-09-08">8</option>
				<option value="2017-09-09">9</option>
				<option value="2017-09-10">10</option>
				<option value="2017-09-11">11</option>
				<option value="2017-09-12">12</option>
				<option value="2017-09-13">13</option>
				<option value="2017-09-14">14</option>
				<option value="2017-09-15">15</option>
				<option value="2017-09-16">16</option>
				<option value="2017-09-17">17</option>
				<option value="2017-09-18">18</option>
				<option value="2017-09-19">19</option>
				<option value="2017-09-20">20</option>
				<option value="2017-09-21">21</option>
				<option value="2017-09-22">22</option>
				<option value="2017-09-23">23</option>
				<option value="2017-09-24">24</option>
				<option value="2017-09-25">25</option>
				<option value="2017-09-26">26</option>
				<option value="2017-09-27">27</option>
				<option value="2017-09-28">28</option>
				<option value="2017-09-29">29</option>
				<option value="2017-09-30">30</option>
			</select>
			<span>2017年10月</span>
			<select class="ui-choose" multiple="multiple" id="uc_04" name="posTypeSelect[]">
				<option value="2017-10-01">1</option>
				<option value="2017-10-02">2</option>
				<option value="2017-10-03">3</option>
				<option value="2017-10-04">4</option>
				<option value="2017-10-05">5</option>
				<option value="2017-10-06">6</option>
				<option value="2017-10-07">7</option>
				<option value="2017-10-08">8</option>
				<option value="2017-10-09">9</option>
				<option value="2017-10-10">10</option>
				<option value="2017-10-11">11</option>
				<option value="2017-10-12">12</option>
				<option value="2017-10-13">13</option>
				<option value="2017-10-14">14</option>
				<option value="2017-10-15">15</option>
				<option value="2017-10-16">16</option>
				<option value="2017-10-17">17</option>
				<option value="2017-10-18">18</option>
				<option value="2017-10-19">19</option>
				<option value="2017-10-20">20</option>
				<option value="2017-10-21">21</option>
				<option value="2017-10-22">22</option>
				<option value="2017-10-23">23</option>
				<option value="2017-10-24">24</option>
				<option value="2017-10-25">25</option>
				<option value="2017-10-26">26</option>
				<option value="2017-10-27">27</option>
				<option value="2017-10-28">28</option>
				<option value="2017-10-29">29</option>
				<option value="2017-10-30">30</option>
				<option value="2017-10-31">31</option>
			</select>
			<span>2017年11月</span>
			<select class="ui-choose" multiple="multiple" id="uc_04" name="posTypeSelect[]">
				<option></option>
				<option></option>
				<option></option>
				<option value="2017-11-01">1</option>
				<option value="2017-11-02">2</option>
				<option value="2017-11-03">3</option>
				<option value="2017-11-04">4</option>
				<option value="2017-11-05">5</option>
				<option value="2017-11-06">6</option>
				<option value="2017-11-07">7</option>
				<option value="2017-11-08">8</option>
				<option value="2017-11-09">9</option>
				<option value="2017-11-10">10</option>
				<option value="2017-11-11">11</option>
				<option value="2017-11-12">12</option>
				<option value="2017-11-13">13</option>
				<option value="2017-11-14">14</option>
				<option value="2017-11-15">15</option>
				<option value="2017-11-16">16</option>
				<option value="2017-11-17">17</option>
				<option value="2017-11-18">18</option>
				<option value="2017-11-19">19</option>
				<option value="2017-11-20">20</option>
				<option value="2017-11-21">21</option>
				<option value="2017-11-22">22</option>
				<option value="2017-11-23">23</option>
				<option value="2017-11-24">24</option>
				<option value="2017-11-25">25</option>
				<option value="2017-11-26">26</option>
				<option value="2017-11-27">27</option>
				<option value="2017-11-28">28</option>
				<option value="2017-11-29">29</option>
				<option value="2017-11-30">30</option>
			</select>
			<span>2017年12月</span>
			<select class="ui-choose" multiple="multiple" id="uc_04" name="posTypeSelect[]">
				<option></option>
				<option></option>
				<option></option>
				<option></option>
				<option></option>
				<option value="2017-12-01">1</option>
				<option value="2017-12-02">2</option>
				<option value="2017-12-03">3</option>
				<option value="2017-12-04">4</option>
				<option value="2017-12-05">5</option>
				<option value="2017-12-06">6</option>
				<option value="2017-12-07">7</option>
				<option value="2017-12-08">8</option>
				<option value="2017-12-09">9</option>
				<option value="2017-12-10">10</option>
				<option value="2017-12-11">11</option>
				<option value="2017-12-12">12</option>
				<option value="2017-12-13">13</option>
				<option value="2017-12-14">14</option>
				<option value="2017-12-15">15</option>
				<option value="2017-12-16">16</option>
				<option value="2017-12-17">17</option>
				<option value="2017-12-18">18</option>
				<option value="2017-12-19">19</option>
				<option value="2017-12-20">20</option>
				<option value="2017-12-21">21</option>
				<option value="2017-12-22">22</option>
				<option value="2017-12-23">23</option>
				<option value="2017-12-24">24</option>
				<option value="2017-12-25">25</option>
				<option value="2017-12-26">26</option>
				<option value="2017-12-27">27</option>
				<option value="2017-12-28">28</option>
				<option value="2017-12-29">29</option>
				<option value="2017-12-30">30</option>
				<option value="2017-12-31">31</option>
			</select>
		</div>
	</div>
		<!--<div class="form-cell">
			<ul>
				<li><textarea id="content" name="content" placeholder="请详细描述情况" rows="6"></textarea></li>		
			</ul>
		</div>-->
	<div class="form-group">
		<div class="publish-article-content">
			<div class="title-tips">详细内容</div>
			<div class="content-box"><div contenteditable="true" class="article-content" id="content">请填写内容或上传图片</div></div>
		</div>
		<div class="form-img">
			<a class="file" href="javascript:;">
				<span>上传图片</span>
				<input type="file" name="file" id="uploadImg">
			</a>
		</div>	
	</div>
	<div class="form-button"><input name="s" type="submit" id="s" value="提&nbsp;&nbsp;交"></div>
	<div class="form-readme"><p>我已阅读并同意<font color="#0099FF">《网演中国服务条款》</font></p></div>
</div>
</form>

<footer id="bar-fixed">
	<a href="../" class="tab-item"><i class="icon-tabbar bar-home"></i>首页</a>
	<a href="../category.php" class="tab-item"><i class="icon-tabbar bar-message"></i>分类</a>
	<a href="../publish/" class="tab-item active"><i class="icon-tabbar bar-publish2"></i>发布</a>	
	<a href="../user/" class="tab-item"><i class="icon-tabbar bar-user"></i>我</a>
</footer>
<script src="../js/frameJS/jquery-2.1.1.min.js" type="text/javascript" charset="utf-8"></script>
<script src="../js/frameJS/localResizeIMG-master/dist/lrz.bundle.js" type="text/javascript" charset="utf-8"></script>
<script src="../js/frameJS/bootstrap.min.js" type="text/javascript" charset="utf-8"></script>
<script src="../js/frameJS/layer/layer.js" type="text/javascript" charset="utf-8"></script>
<script type="text/javascript">
			$(function() {

				//加载公共头部
				$('header').load('../commonTemplate/common-header.html');
				
				//上传缩略图
				$('#uploadThumb').on('change', function() {
					// this.files[0] 是用户选择的文件
					lrz(this.files[0], {
							width: 1024,
							quality:0.7
					})
					.then(function(rst) {
						// 把处理的好的图片给用户看看呗
						var $imgList = document.getElementById('imgList');
						var img = new Image();
						img.src = rst.base64;
						//document.write(img.src);
						$.ajax({
         					url: "publish-thumbup.php",
         					type: "POST",
         					data:{trans_data:img.src,trans_id:'<?php echo $code;?>'},
         					//dataType: "json",
         					error: function(){  
          					   alert('Error loading XML document');  
        					},  
         					success: function(data,status){//如果调用php成功    
             				//alert(unescape(data));//解码，显示汉字
         					}
    					});	 
						img.onload = function() {
							layer.msg('上传中...');
							$imgList.appendChild(img);
						};
						
						return rst;
					})

					.then(function(rst) {
						
						// 额外添加参数
						rst.formData.append('fileLen', rst.fileLen);
//						$.ajax({
//						    url: 'http://koa-upload.coding.io', // 这个地址做了跨域处理，可以用于实际调试
//						    data: rst.formData,
//						    processData: false,
//						    contentType: false,
//						    type: 'POST',
//						    success: function (data) {
//						        config(JSON.stringify(data));
//						    }
//						});
						return rst;
					})

					.catch(function(err) {
						// 万一出错了，这里可以捕捉到错误信息
						// 而且以上的then都不会执行

						alert(err);
					})

					.always(function() {
						// 不管是成功失败，这里都会执行
					});
				});
				//上传图片
				$('#uploadImg').on('change', function() {
					// this.files[0] 是用户选择的文件
					lrz(this.files[0], {
							width: 1024,
							quality:0.7
					})
					.then(function(rst) {
						// 把处理的好的图片给用户看看呗
						var $imgList = document.getElementById('content');
						var img = new Image();
						img.src = rst.base64;
						//document.write(img.src);
						$.ajax({
         					url: "publish-photoup.php",
         					type: "POST",
         					data:{trans_data:img.src,trans_id:'<?php echo $code;?>'},
         					//dataType: "json",
         					error: function(){  
          					   alert('Error loading XML document');  
        					},  
         					success: function(data,status){//如果调用php成功    
             				//alert(unescape(data));//解码，显示汉字
							var str = data;
							$("#content").append(str);
         					}
    					});	 
						img.onload = function() {
							layer.msg('上传中...');
							//$imgList.appendChild(img);
						};
						
						return rst;
					})

					.then(function(rst) {
						
						// 额外添加参数
						rst.formData.append('fileLen', rst.fileLen);
//						$.ajax({
//						    url: 'http://koa-upload.coding.io', // 这个地址做了跨域处理，可以用于实际调试
//						    data: rst.formData,
//						    processData: false,
//						    contentType: false,
//						    type: 'POST',
//						    success: function (data) {
//						        config(JSON.stringify(data));
//						    }
//						});
						return rst;
					})

					.catch(function(err) {
						// 万一出错了，这里可以捕捉到错误信息
						// 而且以上的then都不会执行

						alert(err);
					})

					.always(function() {
						// 不管是成功失败，这里都会执行
					});
				});
			})
		</script>
<!--<script src="../js/src/jquery-1.11.0.min.js"></script>-->
<script src="../js/src/ui-choose.js"></script>
<script>
	// 将所有.ui-choose实例化
	$('.ui-choose').ui_choose();
	// uc_04 select 多选
	var uc_04 = $('#uc_04').ui_choose();
	uc_04.click = function(value, item) {
	    console.log('click', value);
	};
	uc_04.change = function(value, item) {
	    console.log('change', value);
	};
</script>
</body>
</html>